home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / ae / code / ax3.00 / chat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-03  |  3.7 KB  |  184 lines

  1. #include "bbs.h"
  2.  
  3.  
  4. int Chat(void)
  5. {
  6.  extern int  ChatSerFlag,ChatConFlag;
  7.  extern struct myst my_struct;
  8.  register int c;
  9.  int j,x,i,back,WhichCon,WhichSer;
  10.  char str[100],str2[10],SPACE[90],buff[256];
  11.  FILE *fp;
  12.  
  13.  /* check for out cycled chat start sayings */
  14.  if(my_struct.startchatnum > 0) {   /* do we have a chat file ?? */
  15.      if(!(fp = fopen(my_struct.startchatfile,"r")))
  16.              goto wx;
  17.  
  18.      buff[0] = '\0';
  19.      j = rand() % my_struct.startchatnum;
  20.      i = 0;
  21.      while(fgets(buff,80,fp)!=0) {
  22.        if(i >= j) break;
  23.        i++;
  24.      }
  25.      fclose(fp);
  26.      i = 0;
  27.      if(buff[0] == '\0') goto wx;
  28.      sprintf(GSTR1,"\r\n\r\n%s\r\n\r\n",buff);
  29.      AEPutStr(GSTR1);
  30.      goto sx;
  31.  }
  32.  
  33. wx:  Check_Online_Status();
  34.  sprintf(GSTR1,"%sStartChat",NodeStr);
  35.  
  36.  if(!(i=ChecktoDisplay(GSTR1,GSTR2,0,0))) {
  37.      AEPutStr("\r\n\r\nThis is ");
  38.         AEPutStr(Cmds->SysopName);
  39.         AEPutStr(", How can I help you??\r\n\r\n");
  40.     }
  41.  
  42. sx:
  43.  PagedFlag=0;
  44.  ChatConFlag=1;
  45.  if(AnsiColor) {
  46.      sprintf(str,"%dm",Cmds->AcLvl[24]);
  47.      FAEPutStr(str);
  48.     }
  49.  
  50.  ChatSerFlag=0;
  51.  SPACE[0]='\0';
  52.  str[0]='\0';
  53.  x=0;
  54.  while(ChatFlag){
  55.      Next:
  56.         WhichCon=ChatConFlag;
  57.      WhichSer=ChatSerFlag;
  58.         Next2:
  59.      c=ReadChar(KEYBOARD_TIMEOUT);
  60.         if(c==HISTORY)        goto Next2;
  61.      if(ChatFlag==0)        break;
  62.      if(c==NO_CARRIER) { ChatFlag=0; return(NO_CARRIER); }
  63.      if(c=='\003' && GET_BIT(ACS_BREAK_CHAT)) { ChatFlag=0; break; }
  64.         if(c=='\r') {
  65.          if(CaptureFP)
  66.              fprintf(CaptureFP,"%s\n",SPACE);
  67.  
  68.           /***** SIMILATES THE F1 'exit chat' routine *****/
  69.           strupr(SPACE);
  70.  
  71.          SPACE[0]='\0';
  72.             x=0;
  73.             FAEPutStr("\r\n");
  74.             Check_Online_Status();
  75.             goto Next2;
  76.         }
  77.  
  78.         if(c=='\b' || c=='\177') {
  79.          if(x>0)    {
  80.                 x-=1;
  81.                 SPACE[x]='\0';
  82.                 FAEPutStr("\b \b");
  83.                 goto Next2;
  84.             }
  85.             goto Next2;
  86.         }
  87.         if(c==''||c=='\07') {
  88.          SendChar(c);
  89.             goto Next2;
  90.         }
  91.      if(c<' ')        goto Next2;
  92.  
  93.      x+=1;
  94.         if(AnsiColor) {
  95.          if(ChatConFlag==1&&WhichSer==1) {
  96.              sprintf(str,"%dm",Cmds->AcLvl[24]);
  97.                 if(BitPlanes<3)                SerPutStr(str);
  98.              else                           FAEPutStr(str);
  99.             }
  100.          if(ChatSerFlag==1&&WhichCon==1)    {
  101.              sprintf(str,"%dm",Cmds->AcLvl[25]);
  102.                 if(BitPlanes<3)                SerPutStr(str);
  103.                  else                       FAEPutStr(str);
  104.             }
  105.          SendChar(c);
  106.         } else         SendChar(c);
  107.  
  108.      str2[0]=(char)c;
  109.         str2[1]='\0';
  110.         strcat(SPACE,str2);
  111.  
  112.         if(x>78) {
  113.          back=0;
  114.             for(i=x; i>=0; i--)    {
  115.              if(SPACE[i-1]==' ')    {
  116.                  back=x-i;
  117.                     break;
  118.                 }
  119.             }
  120.             if(back==0)    {
  121.              if(CaptureFP)
  122.                  fprintf(CaptureFP,"%s\n",SPACE);
  123.  
  124.              FAEPutStr("\r\n");
  125.                 SPACE[0]='\0';
  126.                 x=0;
  127.                 goto Next;
  128.             }
  129.          str[0]='\0';
  130.             for(i=(x-back); i<x; i++) {
  131.              str2[0]=SPACE[i];
  132.                 str2[1]='\0';
  133.                 strcat(str,str2);
  134.             }
  135.  
  136.          if(CaptureFP) {
  137.              if(x-back-1>=0) {
  138.                  SPACE[x-back-1]='\0';
  139.                 }
  140.                 fprintf(CaptureFP,"%s\n",SPACE);
  141.             }
  142.  
  143.          x=strlen(str);
  144.             strcpy(SPACE,str);
  145.             for(i=0; i<x; i++)
  146.              FAEPutStr("\b \b");
  147.  
  148.             FAEPutStr("\r\n");
  149.             FAEPutStr(str);
  150.         }
  151.     }
  152.  
  153.  (void)StatPrintUser(&User);
  154.  if(AnsiColor)    AEPutStr("");
  155.  
  156.  /*---------------- check for our cycled chat stop sayings ------------*/
  157.  if(my_struct.stopchatnum > 0) {   /* do we have a chat file ?? */
  158.      if(!(fp = fopen(my_struct.stopchatfile,"r")))
  159.              goto wy;
  160.  
  161.      buff[0] = '\0';
  162.      j = rand() % my_struct.stopchatnum;
  163.      i = 0;
  164.      while(fgets(buff,80,fp)!=0) {
  165.        if(i >= j) break;
  166.        i++;
  167.      }
  168.      fclose(fp);
  169.      i = 0;
  170.      if(buff[0] == '\0') goto wy;
  171.      sprintf(GSTR1,"\r\n\r\n%s\r\n",buff);
  172.      AEPutStr(GSTR1);
  173.      return(SUCCESS);
  174.  }
  175.  
  176.  
  177. wy:
  178.  sprintf(GSTR1,"%sEndChat",NodeStr);
  179.  if(!(i=ChecktoDisplay(GSTR1,GSTR2,0,0)))
  180. wz:     AEPutStr("\r\n\r\nEnding Chat.");
  181.  
  182.  return(SUCCESS);
  183. }
  184.